package org.se.scut.hibernate.dao.utils;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class DAOUtils {

	public static <T> Set<T> getByPagination( Set<T> allSet, int from, int count){
		Set<T> paginSet = new HashSet<T>(count);
		int i = 0;
		for (Iterator<T> iterator = allSet.iterator(); iterator.hasNext(); i++) {
			if (from <= i && paginSet.size() < count) {
				paginSet.add((T) iterator.next());
			}		
		}
		return paginSet;
		
	}
	
	public static <T> List<T> getByPagination( List<T> allSet, int from, int count){
		List<T> paginSet = new ArrayList<T>(count);
		int i = 0;
		for (Iterator<T> iterator = allSet.iterator(); iterator.hasNext(); i++) {
			if (from <= i && paginSet.size() < count) {
				paginSet.add((T) iterator.next());
			}		
		}
		return paginSet;
		
	}
	
}
